package com.google.code.chaotic.dto;

import java.util.ArrayList;
import java.util.List;

public class DtoUtils {

	public static List<LatLonDto> extractHabitsEnds( //
			List<CommutingHabitDto> habits, EndType endType) {

		ArrayList<LatLonDto> ends = new ArrayList<LatLonDto>(habits.size());

		for (CommutingHabitDto habit : habits)
			ends.add(endType == EndType.ORIG ? habit.getOrigin() //
					: habit.getDestination());

		return ends;
	}

	public static List<CommutingHabitDto> extractHabits( //
			List<HabitInServiceDto> hisList, boolean cancelleds) {

		ArrayList<CommutingHabitDto> habits = new ArrayList<CommutingHabitDto>(
				hisList.size());

		for (HabitInServiceDto his : hisList)
			if (cancelleds ^ (his.getCancellationTime() == null))
				habits.add(his.getHabit());

		return habits;
	}

	public static List<CommutingHabitDto> extractAllHabits( //
			List<HabitInServiceDto> hisList) {

		ArrayList<CommutingHabitDto> habits = new ArrayList<CommutingHabitDto>(
				hisList.size());

		for (HabitInServiceDto his : hisList)
			habits.add(his.getHabit());

		return habits;
	}
}
